<?php


class Write {
    public $IDLesson;
    public $IDUser;
    public $Content;
    public $Mark;
    public $ListFriend;


    function SaveWrite($IDUser,$IDLesson,$Content) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();
            $Mark = 0;
            
            $sql = "INSERT INTO writeLesson (IDUser ,IDLesson ,Content ,Mark)VALUES 
                ('$IDUser', '$IDLesson','$Content','$Mark');" ;
            $result = $connection->executeQuery($sql);

            $connection->close();
            return true;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }
    
    function SaveMyTagFriend($myTagedFriend, $idUser, $idLesson) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();
            $Mark = 0;
            
            $sql = "UPDATE writelesson SET ListFriend = '$myTagedFriend' WHERE IDUser = $idUser AND IDLesson = $idLesson";
                
            $result = $connection->executeQuery($sql);

            $connection->close();
            return true;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }
    
    function updateContentWrite($idUser, $idLesson,$content) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();
            $Mark = 0;
            
            $sql = "UPDATE writelesson SET Content = '$content' WHERE IDUser = $idUser AND IDLesson = $idLesson";
                
            $result = $connection->executeQuery($sql);

            $connection->close();
            return true;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }
    
    function GetWrite($idUser, $idLesson) {
        try {
             $connection = new MySqlDataAccessHelper();
            $connection->open();
            $write = new Write();
            $sql = "select* from writelesson where IDUser = $idUser AND IDLesson = $idLesson";
            $result = $connection->executeQuery($sql);
            
            while ($row = mysql_fetch_object($result)) {
                $write =$row;
            }
            $connection->close();
            return $write;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }
    
    

}